package com.twotiger.and.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import app.twotiger.p2p.R;
import app.twotiger.p2p.R.color;

import com.twotiger.and.activity.account.invested.InverstedRecordPage;
import com.twotiger.and.bean.Investment;
import com.twotiger.and.util.ArithUtils;
import com.twotiger.and.util.DateUtil;
import com.twotiger.and.util.LogUtil;

public class ProjectDetailrepayAdapter extends BaseAdapter {

    private Context context;
    private List<Investment> list;
    private LayoutInflater inflater;
    private String isCyOrYh;

    public ProjectDetailrepayAdapter(Context context, List<Investment> list, String isCyOrYh) {
        super();
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
        this.isCyOrYh = isCyOrYh;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    MyViewHolder hodler = null;

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = inflater.inflate(R.layout.projectrepayment_layout, null);
        if (hodler == null) {
            hodler = new MyViewHolder();
        }
        hodler.repayment_time = (TextView) view.findViewById(R.id.repayment_time);
        hodler.repayment_capital = (TextView) view.findViewById(R.id.repayment_capital);
        hodler.repayment_interest = (TextView) view.findViewById(R.id.repayment_interest);
        hodler.repayment_status = (TextView) view.findViewById(R.id.repayment_status);
        Investment investment = list.get(position);
        hodler.repayment_time.setText(DateUtil.getDateStringForLong(
            Long.valueOf(investment.getRepaymentTime()), DateUtil.DATE_FMT));
        hodler.repayment_capital.setText(ArithUtils.coverMoneyComma(investment.getCapital()));
        hodler.repayment_interest.setText(investment.getInterest());
        hodler.repayment_status.setText(investment.getStatusName());
        if (InverstedRecordPage.REQTYPE_CYZ.equals(isCyOrYh)) {
            hodler.setFontColor(context.getResources().getColor(color.gray_2)); //未还款，将颜色设为黑色
        } else if (InverstedRecordPage.REQTYPE_YHK.equals(isCyOrYh)) {
            hodler.setFontColor(context.getResources().getColor(color.gray_1)); //已还款，则将颜色设为灰色
        }
        return view;
    }

    class MyViewHolder {
        TextView repayment_time;
        TextView repayment_capital;
        TextView repayment_interest;
        TextView repayment_status;

        //为textview设置颜色
        private void setFontColor(int color) {
            repayment_time.setTextColor(color);
            repayment_capital.setTextColor(color);
            repayment_interest.setTextColor(color);
            repayment_status.setTextColor(color);
        }
    }

}
